<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ClockModel
 *
 * @author BUI VAN UY
 */
class ClockModel extends CFormModel
{

    public $checkIn, $checkOut;
    public $id = 0;
    public $userId;
    public $typeId;
    public $date;
    public $name;
    public $type;

    public function rules()
    {
        return array(
            array('checkIn, checkOut', 'required')
        );
    }

    private $timeStepList;

    public function getTimeStepList()
    {
        if ($this->timeStepList == NULL)
        {
            // Bắt đầu từ lúc 0h
            $startTime = 0 * 60;
            // Kết thúc lúc 24h
            $endTime   = 24 * 60;
            $data      = array();

            for ($i = $startTime; $i <= $endTime; $i+=5)
            {
                $data[$i] = $this->convertIntToTime($i);
            }
            $this->timeStepList = $data;
        }
        return $this->timeStepList;
    }

    private function convertIntToTime($intTime)
    {
        if ($intTime != NULL)
            return intval($intTime / 60) . ":" . str_pad(($intTime % 60), 2, "0", STR_PAD_LEFT);
        else
            return "-";
    }

}

?>
